
import cloud from '@tbmp/mp-cloud-sdk';
cloud.init({
  env: 'online'
});
App({
  cloud,
  globalData: {
    userInfo: {},
    shop_id: '',
  },
  userInfo: null,
  onLaunch(options) {
    //模板数据， 从ext.json的ext中读取
    let schemaData = my.getExtConfigSync && my.getExtConfigSync() || {};
    this.globalData.shop_id = schemaData.shop_id;
    my.authorize({
      scopes: 'scope.userInfo',
      success: (res) => {
        console.log(res)
        my.getAuthUserInfo({
          success: (userInfo) => {
            console.log(userInfo)
            this.globalData.userInfo = userInfo;
            console.log(this.globalData)
            this.addUser()
          }
        })

      },
      fail: (res) => {
        my.alert({
          title: JSON.stringify(res)
        })
      }
    })
  },
  async addUser() {
    const cloud = this.cloud;
    let sendData={
      shop_id:this.globalData.shop_id,
      avatar:this.globalData.userInfo.avatar,
      nickName:this.globalData.userInfo.nickName
    }
    const res = await cloud.application.httpRequest({
      path: '/index.php/index/tb/adduser',
      method: 'POST',
      params: sendData
    })
  }
});
